import { Component, OnInit } from '@angular/core';
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入
import { Router, ActivatedRoute } from "@angular/router"; //路由引入
import { config } from '../../shared/smartadmin.config';
import { id } from '@swimlane/ngx-datatable/release/utils';

declare var $: any;
declare var BMap: any;
declare var Viewer: any;
@Component({
    selector: 'sa-data-review',
    templateUrl: './data-review.component.html',
    styleUrls: ['./data-review.component.css'],
})
export class DataReviewComponent implements OnInit {
    tableData: any[] = []; //table数据
    totalCount: number = 0; //分页总条数
    curPage: number = 1; //分页当前页
    pageSize: number = 10; //内置的分页每页条数
    tableParam: any = {
        carNumber: '',
        source: '',
        startTime: '',
        endTime: '',
        searchKey: '',
        status: ''
    }
    TcarUseList = carTypeListObj.carUseList
    TcarDeatailUseList = carTypeListObj.carDeatailUseList
    constructor(private jsonApiService: JsonApiService, private router: Router, private activatedRoute: ActivatedRoute) {
        activatedRoute.queryParams.subscribe(queryParams => {
            this.curPage = queryParams.nowPage || 1;
        });
    }
    // 接收子组件传递过来的数据 
    getSelectTableTime(time) {
        this.tableParam.startTime = time.startTime;
        this.tableParam.endTime = time.endTime;
    }
    ngOnInit() {
        let that = this;
        System.import('script-loader!select2/dist/js/select2.min.js').then(() => {
            System.import('assets/js/select2-zh-CN.js').then(() => {
                this.select2Car(); //初始化select 2 车辆
            });
        })
        System.import('assets/js/datepicker/js/bootstrap-datetimepicker.min.js').then(() => {
            System.import('assets/js/datepicker/locales/bootstrap-datetimepicker.zh-CN.js').then(() => {
                $("#selfStartTime").datetimepicker({ //自定义开始时间
                    format: "yyyy-mm-dd hh:ii:ss",
                    language: "zh-CN",
                    autoclose: true,
                    minView: 0
                })
                $("#selfEndTime").datetimepicker({ //自定义结束时间插件
                    format: "yyyy-mm-dd hh:ii:ss",
                    language: "zh-CN",
                    autoclose: true,
                    minView: 0
                })
            })
        })
        this.load();
        this.modalMoveExamine();
    }
    // 删除[清空]指定开始时间值
    delSelfStartTime() {
        $("#selfStartTime").val('');
    }
    // 删除[清空]指定结束时间值
    delSelfEndTime() {
        $("#selfEndTime").val('');
    }
    //自定义当前时间
    selefTimeActiveFlag: string = '';
    selefTimeActive(flag) {
        this.selefTimeActiveFlag = flag;
    }
    //table刷新
    refresh() {
        this.load();
    }
    //表格搜索
    tableSearch() {
        this.curPage = 1;
        this.load();
    }
    //分页回调
    paginate(e) {
        this.curPage = e.page + 1;
        this.pageSize = e.rows;
        this.load();
    }
    //初始化加载list数据
    load() {
        let timeCheck = common.correctTimeParams(this.tableParam.startTime, this.tableParam.endTime, 0);
        if (!timeCheck.status) {
            this.jsonApiService.message(timeCheck.message);
            return;
        }
        let data = {
            pageSize: this.pageSize,
            nowPage: this.curPage,
            parameters: {
                deviceId: this.tableParam.deviceId,
                // carNumber: this.tableParam.carNumber,
                startTime: this.tableParam.startTime,
                endTime: this.tableParam.endTime,
                source: this.tableParam.source,
                searchKey: common.stringTrim(this.tableParam.searchKey),
                status: this.tableParam.status
            }
        }
        let reqdata = 'gridPager=' + JSON.stringify(data);
        this.jsonApiService.http("projectCompany/gpsAuditList.html", reqdata).subscribe(data => {
            if (data.isSuccess) {
                var result = data.exhibitDatas;
                if (result && result.length) {
                    for (let row of result) {
                        row.intervalSky = common.secondToDate(row.intervalSky);
                    }
                }
                this.tableData = data.exhibitDatas;
                this.totalCount = data.recordCount;

            } else {
                this.jsonApiService.message(data.message);
            }
        })
    }
    deleteRow(row) {
        this.jsonApiService.confirm_message("此操作将永久删除数据,确认要删除?").then(() => {
            let reqdata = 'id=' + row.id;
            this.jsonApiService.http("projectCompany/delGpsAudit.html", reqdata).subscribe(data => {
                this.jsonApiService.message(data.message);
                this.load();
            })
        })
    }
    //拉取车辆数据
    select2Car() {
        var that = this;
        $("#carNumberSelect2").select2({
            language: "zh-CN",
            placeholder: "请选择",
            allowClear: true,
            minimumInputLength: 2, //最少2个字符，select2才显示查询的内容

            ajax: {
                url: config.BaseURL + "stats/carListByCarNumber.html",
                dataType: 'json',
                delay: 50,
                method: "POST",
                xhrFields: {
                    withCredentials: true
                },
                data: function (params) {
                    return {
                        "carNumber": params.term // search term
                    };
                },
                processResults: function (data, params) {
                    var options = new Array();
                    // 小于10个数量才判断重复
                    if (data.data.length <= 10) {
                        let arr = []
                        let sameCar = []
                        // 判断相同的车牌号
                        for (let index = 0; index < data.data.length; index++) {
                            let car = data.data[index];
                            if (arr.indexOf(car.carNumber) != -1) {
                                sameCar.push(car.carNumber)
                            } else {
                                arr.push(car.carNumber);
                            }
                        }
                        $(data.data).each(function (index, car) {
                            if (sameCar.indexOf(car.carNumber) != -1) {
                                options.push({
                                    id: car.deviceId,
                                    text: car.carNumber + "[" + car.parentName + "]"
                                })
                            } else {
                                options.push({
                                    id: car.deviceId,
                                    text: car.carNumber
                                })
                            }
                        });
                    } else {
                        $(data.data).each(function (index, car) {
                            options.push({
                                id: car.deviceId,
                                text: car.carNumber
                            })
                        });
                    }
                    return {
                        results: options //获取查询后的结果
                    };
                },
                cache: true
            },
            templateResult: this.formatRepo
        }).on("select2:select", function (e) {
            var data = e.params.data;
            that.tableParam.deviceId = data.id;
            if (data.text.indexOf('[') > 0) {
                that.tableParam.carNumber = data.text.split('[')[0];
            } else {
                that.tableParam.carNumber = data.text;
            }
        });
    }
    //select2 格式回调函数
    formatRepo(state) {
        if (!state.id) {
            return state.text
        };
        var $state = $('<span><i class="fa fa-car green"></i>&nbsp;&nbsp;' + state.text + '</span>');
        return $state;
    }
    del_carNumber() {
        this.tableParam.deviceId = '';
        this.tableParam.carNumber = '';
        var str = $("<span class='select2-selection__placeholder'>请选择</span>");
        $('#carNumberSelect2').val("");
        $("#select2-carNumberSelect2-container").empty();
        $("#select2-carNumberSelect2-container").attr("title", "");
        $("#select2-carNumberSelect2-container").prepend(str);
    }

    //导出
    export_data() {
        var parameters = {
            deviceId: this.tableParam.deviceId,
            // carNumber: this.tableParam.carNumber,
            startTime: this.tableParam.startTime,
            endTime: this.tableParam.endTime,
            source: this.tableParam.source,
            searchKey: common.stringTrim(this.tableParam.searchKey),
            status: this.tableParam.status
        };
        let timeCheck = common.correctTime(parameters)
        if (!timeCheck.status) {
            this.jsonApiService.message(timeCheck.message);
            return;
        }
        common.exprotDataFile(parameters, 'param', config.BaseURL + 'projectCompany/gpsAuditListExport.html')
    }
    //批量导出图片
    export_Imgdata() {
        var parameters = {
            deviceId: this.tableParam.deviceId,
            // carNumber: this.tableParam.carNumber,
            startTime: this.tableParam.startTime,
            endTime: this.tableParam.endTime,
            source: this.tableParam.source,
            searchKey: common.stringTrim(this.tableParam.searchKey),
            status: this.tableParam.status
        };
        let timeCheck = common.correctTime(parameters)
        if (!timeCheck.status) {
            this.jsonApiService.message(timeCheck.message);
            return;
        }
        common.exprotDataFile(parameters, 'param', config.BaseURL + 'projectCompany/gpsAuditListExportPicture.html')
    }

    modalMoveExamine() {
        var that = this;
        $('body').undelegate('#headDrag', 'mousedown', function () { });
        $('body').delegate('#headDrag', 'mousedown', function (e) {
            $(this).css("cursor", "move");
            var offset = $('#deviceDetailModal').position();
            var x = e.pageX - offset.left;
            var y = e.pageY - offset.top;
            $(document).bind("mousemove", function (ev) {
                $("#deviceDetailModal").stop();
                var _x = ev.pageX - x;
                var _y = ev.pageY - y;
                if (_y < 0) { //避开头部横条
                    return;
                }
                $("#deviceDetailModal").animate({
                    left: _x + "px",
                    top: _y + "px"
                }, 2);
            });
        });
        $(document).mouseup(function (e) {
            e.cancelBubble = true;
            $(this).unbind("mousemove");
        });
        $('body').undelegate('#dragArrow', 'mousedown', function () { });
        $('body').delegate('#dragArrow', 'mousedown', function (e) {
            let ele = $('#deviceDetailModal');
            let x = e.pageX - ele.width();
            $('body').bind("mousemove", function (ev) {
                $("#deviceDetailModal").stop();
                let _x = ev.pageX - x;
                if (_x < 1200) { //避开头部横条
                    return;
                }
                $("#deviceDetailModal").find('.modal-dialog').animate({
                    width: _x + "px",
                }, 2);
                //				setTimeout(()=>{
                $(window).trigger('resize');
                //				},120)
            });
        });

        $('body').mouseup(function (e) {
            e.cancelBubble = true;
            $(this).unbind("mousemove");
            //			$(window).trigger('resize');
        });
    }
    selectedRow: any = {}; //选中的数据
    deviceBaseInfo: any = {
        companyName: '',
        carNumber: '',
        deviceId: '',
        hwVersion: '',
        useTypeL1: '',
        useTypeL2: '',
        userTypeName: '',
        sensorType: '',
        productNo: '',
        iccid: '',
        driverName: '',
        phone: '',
        inputDate: '',
        installTime: '',
        userNameForCreate: '',
        sensorChannel: [],
        coef: [],
        coefT: [],
        version: '',
        haveRepaired: {},
        logForCoef: {},
        upgradeInfo: {},
        repaired: {},
        isPushText: '',
    };
    versionMessage = {
        name: '',
        alarmType: '',
        versionString: '',
        runStatus: '',
        carUploadDate: '',
        gpsUploadDate: '',
        isShowGPS: false,
    }; //版本信息
    renewalInfo: any = {}; // 车辆的续费信息
    /**
     * 跳转服务费管理页面
     */
    goRenewal() {
        let BaseURL = window.location.protocol + '//' + window.location.hostname + ':' + window.location.port;
        window.open(BaseURL + '#/system/renewal-manage');
    }
    /**
     * 跳转订单监控页面
     */
    JumpOrder(row) {
        let queryParams = {
            id: row.orderId,
            orderCode: row.orderCode,
            startTime: row.fixStartTime,
            endTime: row.fixEndTime
        }
        let BaseURL = window.location.protocol + '//' + window.location.hostname + ':' + window.location.port;
        common.setCookie('reviewFormOrderManagenment', JSON.stringify(queryParams));
        window.open(BaseURL + '#/data-statistics/task/order-management');
    }
    //设备基本信息
    getDeviceBasicInfo(row) {
        this.jsonApiService.http_obj("system/getDeviceBaseInfoByDeviceId.html", {
            deviceId: row.deviceId
        }).subscribe(data => {
            if (data.success && data.data) {
                if (data.data.projectCarInfo) {
                    this.renewalInfo = JSON.parse(JSON.stringify(data.data.projectCarInfo))
                    // 过期判断
                    if (this.renewalInfo.renewalDueTime) {
                        let date = new Date();
                        let now = date.getTime()
                        let overlineDate = new Date(this.renewalInfo.renewalDueTime).getTime()
                        if (overlineDate > now) {
                            this.renewalInfo.isOverDate = "未到期";
                        } else {
                            this.renewalInfo.isOverDate = "已到期";
                        }
                    }
                } else {
                    this.renewalInfo = {}
                }
                for (let item in this.deviceBaseInfo) {
                    if (item === 'coef' || item === 'coefT' || item === 'sensorChannel' || item === 'sensorChannelT') {
                        this.deviceBaseInfo[item] = data.data[item] || [];
                    } else {
                        this.deviceBaseInfo[item] = data.data[item] || '';
                    }
                }
                this.deviceBaseInfo.userTypeName = this.getUseTypeNameL2(this.deviceBaseInfo.useTypeL2);
                if (this.deviceBaseInfo.sensorChannel && this.deviceBaseInfo.sensorChannel.length > 0) {
                    let temArr: any = [];
                    for (var j = 0; j < this.deviceBaseInfo.sensorChannel.length; j++) {
                        let obj = {
                            value: this.deviceBaseInfo.sensorChannel[j],
                            flag: false,
                            isFront: '0'
                        }
                        if (this.deviceBaseInfo.coef) {
                            if (this.deviceBaseInfo.coef[+this.deviceBaseInfo.sensorChannel[j] - 1]) {
                                obj.flag = true;
                            }
                        }
                        if (data.data.sensorAxle && data.data.sensorAxle.length > 0) {
                            obj.isFront = data.data.sensorAxle[j]
                        }
                        //						if(data.data.sensorAxle.length == this.deviceBaseInfo.sensorChannel.length){
                        //							obj.isFront= data.data.sensorAxle[j]
                        //						}
                        temArr.push(obj);
                    }

                    this.deviceBaseInfo.sensorChannelT = temArr;
                    // this.loadSensorModule(this.deviceBaseInfo.sensorChannelT);
                } else {
                    // this.loadSensorModule([]);
                }
                // this.getEditDeviceInfo();//编辑设备信息
                if (this.deviceBaseInfo.coef) {
                    let coefArr = [];
                    for (let i = 0; i < this.deviceBaseInfo.coef.length; i++) {
                        let _item = this.deviceBaseInfo.coef[i];
                        if (_item) {
                            let obj: any = {
                                value: _item,
                                index: i + 1
                            }
                            coefArr.push(obj);
                        }
                    }
                    this.deviceBaseInfo.coefT = coefArr;
                } else {
                    this.deviceBaseInfo.coefT = [];
                }
                if (this.deviceBaseInfo.inputDate) {
                    this.deviceBaseInfo.installTime = common.secondToDate((common.mmsstoTimestamp(common.getNowTime()) - common.mmsstoTimestamp(this.deviceBaseInfo.inputDate)) / 1000)
                }
                if (!this.deviceBaseInfo.repaired) {
                    this.deviceBaseInfo.isPushText = '不限制进厂';
                } else {
                    if (this.deviceBaseInfo.repaired.isPush) {
                        this.deviceBaseInfo.isPushText = '限制进厂';
                    } else {
                        this.deviceBaseInfo.isPushText = '不限制进厂';
                    }
                }
            }
        })
    }
    //根据编码映射对应车辆类型名称
    getUseTypeNameL2(key) {
        if (key) {
            return this.TcarDeatailUseList[key];
        } else {
            return '';
        }
    }
    //获取传感器参数
    getVersionMessage(row) {
        if (!row.deviceId) return;
        this.versionMessage = {
            name: '',
            alarmType: '',
            versionString: '',
            runStatus: '',
            carUploadDate: '',
            gpsUploadDate: '',
            isShowGPS: false,
        }
        let reqdata = 'deviceId=' + row.deviceId;
        this.jsonApiService.http("system/getRealTimeData.html", reqdata).subscribe(result => {
            if (!result.success) return;
            this.versionMessage.name = result.data.version;
            this.versionMessage.runStatus = result.data.runStatus;
            this.versionMessage.carUploadDate = result.data.carUploadDate;
            this.versionMessage.gpsUploadDate = result.data.gpsUploadDate;
            if (result.data.alarmType == '1' || result.data.alarmType == '2') {
                this.versionMessage.alarmType = '[断电中]'
            } else if (result.data.alarmType == '0' || !result.data.alarmType) {
                this.versionMessage.alarmType = '[未知原因]'
            } else if (result.data.alarmType == '3') {
                this.versionMessage.alarmType = '[异常断电]'
            } else if (result.data.alarmType == '4' && result.data.runStatus == '1') {
                this.versionMessage.alarmType = '[回传数据]'
            }
            if (this.versionMessage.carUploadDate && this.versionMessage.gpsUploadDate) {
                let abs = Math.abs(common.mmsstoTimestamp(this.versionMessage.carUploadDate) - common.mmsstoTimestamp(this.versionMessage.gpsUploadDate));
                abs >= 30 * 60 * 1000 ? this.versionMessage.isShowGPS = true : this.versionMessage.isShowGPS = false;
            }
            let coefArr = [];
            if (!result.data.coef) return
            for (let i = 0; i < result.data.coef.length; i++) {
                let item = result.data.coef[i];
                if (item) {
                    let vname = '通道' + (i + 1);
                    coefArr.push(vname + ':' + item);
                }
            }
            let resultString = '';
            for (let _i = 0; _i < coefArr.length; _i++) {
                if (_i < coefArr.length - 1) {
                    resultString += coefArr[_i] + ',';
                } else {
                    resultString += coefArr[_i]
                }
            }
            this.versionMessage.versionString = resultString;

            //警戒线传输
            let timeShadowList = []; //进入围栏在echart显示的阴影区域
            let cordonLineMarkArea = [];
            if (row.dateList.length != 0) {
                for (var i = 0; i < row.dateList.length; i++) {
                    var listObj1 = {
                        xAxis: row.dateList[i].startTime,
                        lineStyle: {
                            type: 'solid'
                        },
                        label: {
                            show: false
                        }
                    }
                    var listObj2 = {
                        xAxis: row.dateList[i].endTime,
                        lineStyle: {
                            type: 'solid'
                        },
                        label: {
                            show: false
                        }
                    }
                    timeShadowList.push(listObj1);
                    timeShadowList.push(listObj2);

                    var MarkAreaList = [{
                        itemStyle: {
                            color: '#ff00ff',
                            opacity: 0.2,
                        },
                        xAxis: row.dateList[i].startTime
                    },
                    {
                        itemStyle: {
                            color: '#ff00ff',
                            opacity: 0.2,
                        },
                        xAxis: row.dateList[i].endTime
                    }
                    ]

                    cordonLineMarkArea.push(MarkAreaList)
                }
            }
            this.repaiTimeList2 = row.dateList;
            this.drawRowData = {
                endTime: $("#selfEndTime").val() ? $("#selfEndTime").val() : row.fixEndTime,
                startTime: $("#selfStartTime").val() ? $("#selfStartTime").val() : row.fixStartTime,
                deviceId: row.deviceId,
                timeShadowList: [],
                cordonLineMarkArea: [],
                coefficient: result.data.coef
            };

            this.drawRowData2 = {
                endTime: $("#selfEndTime").val() ? $("#selfEndTime").val() : row.fixEndTime,
                startTime: $("#selfStartTime").val() ? $("#selfStartTime").val() : row.fixStartTime,
                deviceId: row.deviceId,
                timeShadowList: timeShadowList,
                cordonLineMarkArea: cordonLineMarkArea,
                coefficient: result.data.coef
            };
        })
    }
    // 自定义开始时间绘制地图
    drawMap() {
        if (!$("#selfStartTime").val()) {
            $("#selfStartTime").val(this.selectedRow.fixStartTime);
        }
        if (!$("#selfEndTime").val()) {
            $("#selfEndTime").val(this.selectedRow.fixEndTime);
        }
        let timeCheck = common.correctTimeParams($("#selfStartTime").val(), $("#selfEndTime").val(), 0);
        if (!timeCheck.status) {
            this.jsonApiService.message(timeCheck.message);
            return;
        }
        this.examineDataLoad(this.selectedRow)
        this.getDeviceBasicInfo(this.selectedRow);
        this.getVersionMessage(this.selectedRow);
        this.selefTimeActiveFlag = '';
    }
    //点击弹窗
    isShowExamine: boolean = false;
    rowSelectEvent(row) {
        this.selectedRow = row;
        this.drawRowData = {}
        this.drawRowData2 = {}
        this.isShowExamine = true;
        this.rowId = row.id;
        this.examineUser = row.auditUser;
        this.status = row.status;
        this.auditRemark = '';
        $("#selfStartTime").val(row.fixStartTime);
        $("#selfEndTime").val(row.fixEndTime);
        this.examineDataLoad(row)
        this.getDeviceBasicInfo(row);
        this.getVersionMessage(row);

        $('#deviceDetailModal').show(1);
        $(window).trigger('resize');
    }
    auditRemark: any = ''; //审核意见
    rowId: any = ''; //打开的ID
    status: any = '0' //默认是未审核
    closedeviceDetailModal() {
        $('#deviceDetailModal').hide();
        this.isShowExamine = false
    }
    drawRowData: any;
    drawRowData2: any;
    //画轨迹的数据
    drawTrackArr1: any;
    repaiTimeList2: any;
    runParent1(value) {
        this.drawTrackArr1 = JSON.parse(JSON.stringify(value));
        if (value.type == "clickPoint" && this.selefTimeActiveFlag) {
            $('#' + this.selefTimeActiveFlag).val(value.data.uploadDate);
        }
    }

    drawTrackArr2: any;
    runParent2(value) {
        this.drawTrackArr2 = JSON.parse(JSON.stringify(value));
        if (value.type == "clickPoint" && this.selefTimeActiveFlag) {
            $('#' + this.selefTimeActiveFlag).val(value.data.uploadDate);
        }
    }
    submitExamine(type) {
        let param = {
            id: this.rowId,
            auditRemark: this.auditRemark,
            status: type,
        }
        this.jsonApiService.http_obj("projectCompany/gpsAudit.html", param).subscribe(data => {
            this.jsonApiService.message(data.message);
            if (data.success) {
                $('#deviceDetailModal').hide();
                this.load()
                this.auditRemark = ''
            }
        })
    }

    examineUser: any = '';
    examineDataList: any = []
    examineDataLoad(row) {
        let param = {
            deviceId: row.deviceId,
            startTime: $("#selfStartTime").val() ? $("#selfStartTime").val() : row.fixStartTime,
            endTime: $("#selfEndTime").val() ? $("#selfEndTime").val() : row.fixEndTime,
        }
        this.jsonApiService.http_obj("projectCompany/gpsAuditLogList.html", param).subscribe(data => {
            if (data.success) {
                for (var i = 0; i < data.data.length; i++) {
                    data.data[i].contentList = data.data[i].content.split(',');
                }
                this.examineDataList = data.data;

            } else {
                this.jsonApiService.message(data.message);
            }
        })
    }
    /**
     * 图片上传功能
     */
    imageInfo: any = [];
    fileList: File = null;
    viewer: any;
    isViewer: boolean = false;
    imgUpload: any = {
        id: '',
        describe: 'pathFixCheck',
        businessType: 1, //录车时传入1 维修时传入2 意见反馈传入3 设备损坏返回4 示例图片5
        deviceId: '',
        carNumber: '',
        type: 2, //1返回图片相对路径 2返回图片绝对路径
        imageInfo: this.imageInfo,
        isWaterMarker: 1,
        waterJson: []
    }
    rowImgUpload(row, modal) {
        if (this.isViewer && $(".viewer-container").length > 0) {
            this.viewer.destroy();
        }
        this.imgUpload.id = row.id;
        this.imgUpload.deviceId = row.deviceId;
        this.imgUpload.carNumber = row.carNumber;
        this.imageInfo = row.imageUrl ? JSON.parse(row.imageUrl) : [];
        modal.show();
    }
    //上传多张
    multifileChange(files: FileList) {
        var that = this;
        let multfileList = files;
        let multfileListLen = files.length + that.imageInfo.length;
        if (multfileListLen > 10) {
            this.jsonApiService.message('最多只能上传10张图片');
            return;
        }
        var reqdata = new FormData();
        reqdata.append('describe', this.imgUpload.describe);
        reqdata.append('businessType', this.imgUpload.businessType);
        reqdata.append('deviceId', this.imgUpload.deviceId);
        reqdata.append('type', this.imgUpload.type); //type 1获取相对路径  2获取绝对路径
        reqdata.append('isWaterMarker', this.imgUpload.isWaterMarker);
        this.imgUpload.waterJson = [];
        for (var i = 0; i < multfileList.length; i++) {
            this.fileList = multfileList[i];
            const isJPG = this.fileList.type === 'image/jpeg' || this.fileList.type === 'image/jpg' || this.fileList.type === 'image/png';
            if (!isJPG) {
                this.jsonApiService.message('上传图片只能是 png, jpg, jpeg 格式!');
                return;
            }
            reqdata.append('files', multfileList[i]);
            this.imgUpload.waterJson.push({
                carNumber: this.imgUpload.carNumber,
                time: common.getNowTime(),
            })
        }
        reqdata.append('waterJson', JSON.stringify(this.imgUpload.waterJson));
        this.jsonApiService.form_http("fileUpload/upload.html", reqdata).subscribe(data => {
            if (data.success) {
                for (var i = 0; i < data.data.length; i++) {
                    this.imageInfo.push(data.data[i]);
                }
            }
        })
        for (let k = 0; k < $(".up").length; k++) {
            $(".up")[k].value = null;
        }
    }
    //删除
    deleteImg(i) {
        this.imageInfo.splice(i, 1);
        if (this.isViewer && $(".viewer-container").length > 0) {
            this.viewer.destroy();
        }
    }
    // 取消图片上传
    cancelImgUpload(modal) {
        modal.hide();
    }
    // 图片上传
    submitImgUpload(modal) {
        if (!this.imageInfo || this.imageInfo.length == 0) {
            this.jsonApiService.message('请上传图片后提交');
            return
        }
        let reqdata = {
            id: this.imgUpload.id,
            imageUrl: JSON.stringify(this.imageInfo),
        }
        this.jsonApiService.http_obj("projectCompany/gpsAuditImgUpload.html", reqdata).subscribe(data => {
            if (data.success) {
                this.load();
                modal.hide();
            }
            this.jsonApiService.message(data.message);
        })
    }
    // 图片查看
    rowImg(row, modal) {
        if (this.isViewer && $(".viewer-container").length > 0) {
            this.viewer.destroy();
        }
        this.imgUpload.imageInfo = JSON.parse(row.imageUrl);
        modal.show();
    }
    // 图片查看关闭
    cancelImg(modal) {
        modal.hide();
    }
    /**
     * 图片放大模块
     */
    bigImg: any = '';
    //  viewer2:any;
    bigImgClick(name, img) {
        //         modal.show();
        this.bigImg = img;
        if (this.isViewer && $(".viewer-container").length > 0) {
            System.import('assets/js/viewer/viewer.js').then(
                () => {
                    System.import('assets/js/viewer/bootstrap.bundle.min.js').then(
                        () => {
                            System.import('assets/js/viewer/viewer.css').then(() => {
                                this.showImg(name);
                            })
                        })
                })
        } else {
            this.showImg(name);
        }
    }
    //显示图片组件
    showImg(name) {
        var that = this;
        var imgList = $("." + name)[0];
        this.viewer = new Viewer(imgList, {
            url: 'src',
            title: function (image) {
                return image.alt + ' (' + (this.index + 1) + '/' + this.length + ')';
            },
        });
        that.isViewer = true
    }
    // 放大图片关闭
    CloseBigImg(modal) {
        modal.hide();
    }


    /**
     * 提交GPS审核
     */
    ExamieId: any = ''; //rowId
    Examine: any = {
        source: '1',
        reason: '无GPS'
    }
    sourceList: any = [{
        value: '1',
        text: '客户投诉'
    }, {
        value: '2',
        text: '平台发现'
    }];
    GPSModuleList: any = [
        {
            text: '无GPS',
        }, {
            text: '停车速度平直',
        }, {
            text: '大段丢失',
        }, {
            text: '偶尔丢失',
        }, {
            text: '离线',
        }, {
            text: '断电跑车',
        }
    ]

    closeGPSExamineModal(modal) {
        modal.hide()
    }

    submitGPSExamineModal(modal) {
        if (!this.Examine.reason) {
            this.jsonApiService.message('请选择处理原因');
            return;
        }
        if (!this.Examine.source) {
            this.jsonApiService.message('问题来源');
            return;
        }

        let reqdata = {
            id: this.ExamieId,
            source: this.Examine.source,
            handleReason: this.Examine.reason
        }
        this.jsonApiService.http_obj("projectCompany/editAuditInfo.html", reqdata).subscribe(data => {
            if (data.success) {
                this.load();
                modal.hide();
            }
            this.jsonApiService.message(data.message);
        })
    }

    sourceChange(value) {
        this.Examine.source = value
    }

    reasonChange(value) {
        this.Examine.reason = value
    }
    editRow(row, modal) {
        this.ExamieId = row.id;
        this.Examine.reason = row.handleReason;
        this.Examine.source = row.source;

        modal.show();
    }
}